#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：partial_codes-master 
@File ：msg_receiver.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/2/23 23:56 
"""

import socket

HOST = '127.0.0.1'
PORT = 65432

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if data:
                try:
                    print(data.decode())
                except UnicodeDecodeError:
                    data = data.replace(b'\x00', b'')
                    print(data.decode('utf-8', errors='replace'))
